package Saturday;

import java.util.*;

public class Person {
	private String name;
	private Calendar birthday;
	private boolean gender;
	private Person partner;
	
	public Person(String name, Calendar birthday, boolean gender){
		super();
		this.name=name;
		this.birthday=birthday;
		this.gender=gender;		
	}
	
	public boolean marry(Person p){
		if(this.gender==p.gender){
			System.out.println("同性不能结婚");
			return false;
		}
		if(this.partner!=null || p.partner!=null){
			System.out.println("某一方已婚，不能再结婚");
			return false;
		}
		if(!this.wasOverAgeForMarry()){
			System.out.println("对不起，您的对象没有达到结婚年龄，不能结婚！");
			return false;			
		}
		if(!p.wasOverAgeForMarry()){
			System.out.println("对不起，你的对象没有达到结婚年龄，不能结婚！");
			return false;
		}
		
		this.partner=p;
		p.partner=this;
		System.out.println("恭喜，"+this.name+"和"+p.name+"结婚成功");
		return true;
	}
		
		public boolean wasOverAgeForMarry(){
			if(this.gender && this.getAge()>=22){
				return true;
			}
			if(!this.gender && this.getAge()>=20){
				return true;				
			}
			return false;
		}
		
		public int getAge(){
			Calendar today=new GregorianCalendar();
			int todayYear=today.get(Calendar.YEAR);
			int todayMonth=today.get(Calendar.MONTH);
			int todayDay=today.get(Calendar.DAY_OF_MONTH);
			
			int birthYear=birthday.get(Calendar.YEAR);
			return 0;
		}
}
